<template>
  <div>
    <el-dropdown @command="click">
      <span style="font-size:18px;"><svg-icon icon-class="language" /></span>
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="zh">中文</el-dropdown-item>
        <el-dropdown-item command="en">English</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: 'Lang',
  methods: {
    click(e) {
      console.log(this.$i18n);
              if (this.language == "EN"){
                localStorage.setItem("locale", "zh");
                this.$i18n.locale = localStorage.getItem("locale");
                this.$message({
                  message:"切换为中文！",
                  type:"success"
                });
                localStorage.setItem("lang", "ZH");
                this.language = "ZH";
                location.reload(); //重新加载
              } else if (this.language == "ZH"){
                localStorage.setItem("locale", "en");
                this.$i18n.locale = localStorage.getItem("locale");
                this.$message({
                  message:"Switch to English!",
                  type:"success"
                });
                localStorage.setItem("lang", "EN");
                this.language = "EN";
                location.reload();
    }
  }
}
</script>

<style scoped>
.screenfull-svg {
  display: inline-block;
  cursor: pointer;
  fill: #5a5e66;;
  width: 20px;
  height: 20px;
  vertical-align: 10px;
}
</style>
